'''
Created on Jan 15, 2012

@author: mariano
'''
from multineuro.sprite import ImgSprite
import pygame
from metacog.utilities.score_utilities import ScoreSpriteUtility
from metacog.configuration import SCORE_CONTAINER_FILE

class ScoreSprite(ImgSprite):
    '''
    classdocs
    '''


    def __init__(self):
        '''
        Constructor
        '''
        super(ScoreSprite, self).__init__(SCORE_CONTAINER_FILE)
        helper = ScoreSpriteUtility()
        self.available_positions = helper.generate_initial_positions()
        self.current_position = 0


    def _draw_circle(self, color):
        """ Draws a circle of the given color in the current position. """
        pygame.draw.circle(self.image, color,
                           self.available_positions[self.current_position],
                           12)

    def change_score(self, score):
        """ Given a score, this updates the score shown. """
        assert score != self.current_position
        diff = abs(self.current_position - score)
        direction = cmp(score, self.current_position)
        color = (255, 0, 0)
        if direction < 0:
            color = (255, 255, 255)

        i = 0
        while i < diff:
            self._draw_circle(color)
            self.current_position += direction
            i += 1
        if direction < 0:
            self._draw_circle(color)
        self.dirty = 1



